﻿// <copyright file="BoolToBrushConverter.cs" company="Soumya Chattopadhyay">
// Copyright (c) 2010 All Right Reserved
// </copyright>
// <disclaimer> This software is intented for educational purposes only and not for 
// commerical or prodution use. The software is provided "as is", without warranty 
// of any kind, express or implied, including but not limited to the warranties of 
// merchantability, fitness for a particular purpose and noninfringement. In no event 
// shall the author(s) or copyright holder(s) be liable for any claim, damages or other 
// liability, whether in an action of contract, tort or otherwise, arising from, out of 
// or in connection with the software or the use or other dealings in the software.
// </disclaimer>

namespace My.CodePlex.TFSExplorer.Utilities.Converters
{
    using System;
    using System.Collections.Generic;
    using System.Globalization;
    using System.Linq;
    using System.Text;
    using System.Windows.Data;
    using System.Windows.Markup;
    using System.Windows.Media;

    /// <summary>
    /// Converts a bool to a brush
    /// </summary>
    [ValueConversion(typeof(bool), typeof(System.Windows.Media.Brush))]
    public class BoolToBrushConverter : MarkupExtension, IValueConverter
    {
        /// <summary>
        /// The value provider
        /// </summary>
        /// <param name="serviceProvider">The parameter is not used.</param>
        /// <returns>The converter</returns>
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            return this;
        }

        /// <summary>
        /// Convert from bool to a color
        /// </summary>
        /// <param name="value">The bool value</param>
        /// <param name="targetType">The parameter is not used.</param>
        /// <param name="parameter">The parameter is not used.</param>
        /// <param name="culture">The parameter is not used.</param>
        /// <returns>The color value</returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is bool)
            {
                bool source = (bool)value;
                if (source)
                {
                    return new SolidColorBrush(Colors.Red);
                }
                else
                {
                    return Colors.Black;
                }
            }

            // Default color
            return Colors.Black;
        }

        /// <summary>
        /// Convert a color to bool
        /// </summary>
        /// <param name="value">The parameter is not used.</param>
        /// <param name="targetType">The parameter is not used.</param>
        /// <param name="parameter">The parameter is not used.</param>
        /// <param name="culture">The parameter is not used.</param>
        /// <returns>The parameter is not used.</returns>
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            // No need to convert back
            return null;
        }
    }
}
